import { defineStore } from "pinia"
import axios from 'axios'
import { handleError } from '@/plugins/err-handle'

export const useTerminalStore = defineStore("terminal", {
  state: () => ({
    terminals: [],
    total_count: 0,
    currentTerminal: {}
  }),
  getters: {
    // doubleCount: (state) => state.counter + 2,
  },
  actions: {
    // 列表
    fetchItems(data) {
      return new Promise((resolve, reject) => {
        // 表单数据
        axios.get('/admin/terminal', data)
          .then((response) => {
            // console.log('terminal model 2', response) 
            this.terminals = response.data.data
            this.total_count = response.data.meta.total_count
            resolve(response)
          })
          .catch((err) => {
            handleError(err)
            reject(err)
          })
        })
    },

  },
})